package de.wellenblau.wow3D
{
	import fr.seraf.wow.core.WOWEngine;
	import fr.seraf.wow.core.data.WVector;
	import fr.seraf.wow.primitive.WOWPlane;
	
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.scenes.Scene3D;
	
	public class physicPapervision
	{
		private var _scene:Scene3D;
		private var _wow:WOWEngine;
		private var _ground:physicPlane3D;
		
		public function physicPapervision(scene:Scene3D)
		{
			_scene = scene;
			init();
		}
		
		private function init():void{			
			_wow = new WOWEngine();
			_wow.collisionResponseMode = _wow.SELECTIVE;
			_wow.addMasslessForce(new WVector(0,-1,0));
		}
		
		public function get getWOW():WOWEngine{
			return _wow;
		}
		
		
		public function createGround():void{
			_ground = new physicPlane3D(0,0,0,300,new WireframeMaterial(0xaaaaaa));
			
			add(_ground);
			
			with(_ground.getPhysicObject() as WOWPlane){
				friction = 0.3;
				setRotation(0,0,180);  
			}
		}
		
		public function add(po:physicDisplayObject3D):void{
			po.createPhysicObjet(_wow);
			_scene.addChild(po as DisplayObject3D);
		}
		
		public function update():void{
			
			//WOW calc the next step
			_wow.step();
			
			//sync all positions for every object in scene
			for each(var po:physicDisplayObject3D in _scene.children){
				po.syncObjects();
			}
		}
	}
}